package com.lb.jwitter.action;

import java.io.File;
import java.text.DateFormat;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList; 
import java.util.Collection; 
import java.util.Date; 
import java.util.GregorianCalendar;
import java.util.Locale;

import com.lb.jwitter.service.ConditionReport; 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
import com.lb.jwitter.util.Message; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import java.util.List; 
import java.util.Map; 

import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;


import com.lb.jwitter.util.ApplicationContextProvider; 
import com.opensymphony.xwork2.ActionContext; 
import com.opensymphony.xwork2.Action; 

import com.lb.jwitter.service.TblQLDTTXAChuongTrinhHoc;
import com.lb.jwitter.service.TblQLDTTXAChuongTrinhHocChiTiet;
import com.lb.jwitter.service.TblQLDTTXAChuongTrinhHocChiTietService;
import com.lb.jwitter.service.TblQLDTTXAChuongTrinhHocService;
import com.lb.jwitter.service.TblQLDTTXADMKetQuaXetTuyen;
import com.lb.jwitter.service.TblQLDTTXADMKetQuaXetTuyenService;
import com.lb.jwitter.service.TblQLDTTXADMKhoa;
import com.lb.jwitter.service.TblQLDTTXADMKhoaHoc;
import com.lb.jwitter.service.TblQLDTTXADMKhoaHocService;
import com.lb.jwitter.service.TblQLDTTXADMKhoaService;
import com.lb.jwitter.service.TblQLDTTXADMNganh;
import com.lb.jwitter.service.TblQLDTTXADMNganhService;
import com.lb.jwitter.service.TblQLDTTXADMTrangThaiHocVien;
import com.lb.jwitter.service.TblQLDTTXADMTrangThaiHocVienService;
import com.lb.jwitter.service.TblQLDTTXAHoSoDiemTong;
import com.lb.jwitter.service.TblQLDTTXAHoSoDiemTongService;
import com.lb.jwitter.service.TblQLDTTXAHocVien;
import com.lb.jwitter.service.TblQLDTTXAHocVienChuongTrinhHoc;
import com.lb.jwitter.service.TblQLDTTXAHocVienChuongTrinhHocService;
import com.lb.jwitter.service.TblQLDTTXAHocVienHocPhiBienLai;
import com.lb.jwitter.service.TblQLDTTXAHocVienHocPhiBienLaiService;
import com.lb.jwitter.service.TblQLDTTXAHocVienPhieuLyLich;
import com.lb.jwitter.service.TblQLDTTXAHocVienPhieuLyLichService;
import com.lb.jwitter.service.TblQLDTTXAHocVienService;
import com.lb.jwitter.service.TblQLDTTXAHocVienTaiKhoan;
import com.lb.jwitter.service.TblQLDTTXAHocVienTaiKhoanService;
import com.lb.jwitter.service.TblQLDTTXALop;
import com.lb.jwitter.service.TblQLDTTXALopService;
import com.lb.jwitter.service.TblQLDTTXAQuiDinhHocPhi;
import com.lb.jwitter.service.TblQLDTTXAQuiDinhHocPhiService;
import com.lb.jwitter.service.TblQLDTTXAThongBaoTuyenSinh;

import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.lb.jwitter.service.TblQLDTTXAHoSoDiemXetTuyen;
import com.lb.jwitter.service.TblQLDTTXAHoSoDiemXetTuyenService;

import com.lb.jwitter.service.TblQLDTTXAHoSoXetTuyen;
import com.lb.jwitter.service.TblQLDTTXAHoSoXetTuyenService;
import com.lb.jwitter.service.TblQLDTTXADMThangDiem;


 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class NhapHocAction{

	private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    private int page; 
    public int getPage() { return page; }

    private int pages; 
    public int getPages() { return pages; }
    private String dataString; 
    public String getDataString() { return dataString; }
    
    private Message msg; 
    public Message getMsg() { return msg; }



    private TblQLDTTXAHoSoDiemXetTuyen tblQLDTTXAHoSoDiemXetTuyen; 
    public TblQLDTTXAHoSoDiemXetTuyen getTblQLDTTXAHoSoDiemXetTuyen () {
        return this.tblQLDTTXAHoSoDiemXetTuyen ;
 }

    private Collection<TblQLDTTXAHoSoDiemXetTuyen> tblQLDTTXAHoSoDiemXetTuyens; 
    public Collection<TblQLDTTXAHoSoDiemXetTuyen> getTblQLDTTXAHoSoDiemXetTuyens() {
        return this.tblQLDTTXAHoSoDiemXetTuyens; 
      } 

    private TblQLDTTXAHoSoDiemXetTuyenService tblQLDTTXAHoSoDiemXetTuyenService; 

    private Collection<TblQLDTTXAHoSoXetTuyen> tblQLDTTXAHoSoXetTuyens; 
    public Collection<TblQLDTTXAHoSoXetTuyen> getTblQLDTTXAHoSoXetTuyens() {
         return this.tblQLDTTXAHoSoXetTuyens; 
    }

    private TblQLDTTXAHoSoXetTuyenService tblQLDTTXAHoSoXetTuyenService;
    
    private TblQLDTTXAQuiDinhHocPhiService tblQLDTTXAQuiDinhHocPhiService;
    private TblQLDTTXAHocVienHocPhiBienLaiService tblQLDTTXAHocVienHocPhiBienLaiService;
    private TblQLDTTXAHocVienTaiKhoanService tblQLDTTXAHocVienTaiKhoanService;

    private Collection<TblQLDTTXADMThangDiem> tblQLDTTXADMThangDiems; 
    public Collection<TblQLDTTXADMThangDiem> getTblQLDTTXADMThangDiems() {
         return this.tblQLDTTXADMThangDiems; 
    }

	  private TblTaiKhoan taiKhoanDangNhap; 
	 public TblTaiKhoan getTaiKhoanDangNhap() { 
	     return taiKhoanDangNhap; 
	 } 
	 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
	     this.taiKhoanDangNhap = taiKhoanDangNhap; 
	 } 
	 private TblQuyenChiTietService tblQuyenChiTietService;
		 @Autowired // Injected by Spring 
	     ApplicationContextProvider contextProvider; 


	
	
	 private String hoTen;

	 private TblQLDTTXADMKhoaService tblQLDTTXADMKhoaService;
	 private TblQLDTTXADMKhoaHocService tblQLDTTXADMKhoaHocService;
	 private List<TblQLDTTXADMKhoaHoc> tblQLDTTXADMKhoaHocs; 
	 private TblQLDTTXALopService tblQLDTTXALopService;
	 private TblQLDTTXADMTrangThaiHocVienService tblQLDTTXADMTrangThaiHocVienService;
	 private TblQLDTTXAHocVienService tblQLDTTXAHocVienService; 
	 private TblQLDTTXAHocVienPhieuLyLichService tblQLDTTXAHocVienPhieuLyLichService; 
	 
	 private TblQLDTTXAHocVienChuongTrinhHocService tblQLDTTXAHocVienChuongTrinhHocService;
	 
	 
	 private TblQLDTTXAChuongTrinhHocService tblQLDTTXAChuongTrinhHocService;
	 
	 private TblQLDTTXAChuongTrinhHocChiTietService tblQLDTTXAChuongTrinhHocChiTietService;
	 
	 
	 private List<TblQLDTTXALop> tblQLDTTXALops;
	 private TblQLDTTXADMNganhService tblQLDTTXADMNganhService;
	 
	 private List<TblQLDTTXADMNganh> tblQLDTTXADMNganhs;
	 
	 private TblQLDTTXADMKhoa tblQLDTTXADMKhoa;
	 private Double diemDat;
	 private Long khoaId;
	 
	 private Date today;
	 private List<TblQLDTTXADMKhoa> tblQLDTTXADMKhoas;

	 /**************************************************
	  * FORM 
	  * @return
	  * @throws Exception
	  ***************************************************/
  public String form() throws Exception 
{ 
 try{ 	
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
     
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient");
    
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HoSoXetTuyen", "xem")){ 
        return "noprivilege"; 
    } 
    
    //////////////////get Service

    tblQLDTTXADMKhoaService = (TblQLDTTXADMKhoaService) context.getBean("tbl_QLDTTXA_DM_KhoaClient");

    tblQLDTTXADMKhoaHocService = (TblQLDTTXADMKhoaHocService) context.getBean("tbl_QLDTTXA_DM_KhoaHocClient");

    tblQLDTTXADMNganhService = (TblQLDTTXADMNganhService) context.getBean("tbl_QLDTTXA_DM_NganhClient");

    tblQLDTTXALopService = (TblQLDTTXALopService) context.getBean("tbl_QLDTTXA_LopClient");

	tblQLDTTXAHoSoXetTuyenService = (TblQLDTTXAHoSoXetTuyenService) context.getBean("tbl_QLDTTXA_HoSoXetTuyenClient");

	
	
	
	today = new Date();
      List<ConditionReport> cons = new ArrayList<ConditionReport>(); 

      //dm khoa
	  if(khoaId != null && khoaId != 0){
		  tblQLDTTXADMKhoa = tblQLDTTXADMKhoaService.gettblQLDTTXADMKhoa(khoaId);
			 
	  } else {
		    tblQLDTTXADMKhoa = tblQLDTTXADMKhoaService.gettblQLDTTXADMKhoa(new Long(1));
	  }
	  
	  if(true){
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("id");
		    con.setValue1("desc");
		    con.setOperator("order");
		    cons.add(con);
	  }
	  tblQLDTTXADMKhoas = tblQLDTTXADMKhoaService.findtblQLDTTXADMKhoaByCondition(cons, 0, 0);
	  
		tblQLDTTXADMKhoaHocs = tblQLDTTXADMKhoaHocService.findtblQLDTTXADMKhoaHocByCondition(cons, 0, 0);
		tblQLDTTXADMNganhs = tblQLDTTXADMNganhService.findtblQLDTTXADMNganhByCondition(cons, 0, 0);
		tblQLDTTXALops = tblQLDTTXALopService.findtblQLDTTXALopByCondition(cons, 0, 0);

      ////////////get HoSo XetTuyen
      cons.clear();
	  
	  if(true){
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("trangThaiId");
		    con.setValue1(21);
		    con.setOperator("eq");
		    cons.add(con);
	  }

	  if(khoaId != null && khoaId != 0){
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("khoaId.id");
		    con.setValue1(khoaId);
		    con.setOperator("eq");
		    cons.add(con);
	  } else {
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("khoaId.id");
		    con.setValue1(new Long(1));
		    con.setOperator("eq");
		    cons.add(con);
	  }
	  
	  if(true){
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("ten");
		    con.setValue1("asc");
		    con.setOperator("order");
		    cons.add(con);
	  }
	  if(true){
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("hoTen");
		    con.setValue1("asc");
		    con.setOperator("order");
		    cons.add(con);
	  }
	  
	  if(pageSize == 0) pageSize = 20;
	  if(page == 0) page = 1;
	  
	  tblQLDTTXAHoSoXetTuyens = tblQLDTTXAHoSoXetTuyenService.findtblQLDTTXAHoSoXetTuyenByCondition(cons, pageSize, page); 
	  pages = tblQLDTTXAHoSoXetTuyenService.counttblQLDTTXAHoSoXetTuyenByCondition(cons)/pageSize + 1;
	  
	  cons.clear();
	  
	  dataString ="";
	  dataString += "khoaId=" + khoaId;

	  return Action.SUCCESS; 
	  
      } 
      catch(Exception e){ 
      System.out.println("Loi Form tbl_QLDTTXA_HoSo_DiemXetTuyen Action"); 
     e.printStackTrace(); 
    return Action.ERROR; 
 } 
 } 
 
  
	 /**************************************************
	  * SAVE 
	  * @return
	  * @throws Exception
	  ***************************************************/

  private String saveStr;
  public String save() throws Exception 
  { 
   try{ 	
       Map session = ActionContext.getContext().getSession();
       taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
       if( taiKhoanDangNhap == null) return "noprivilege";
       
      ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
      
      tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient");
      
      if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HoSoXetTuyen", "sua")
         || !tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HocVien", "them")
         || !tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HocVien_PhieuLyLich", "them")
         || !tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HocVien_ChuongTrinhHoc", "them")
    	  
      ){ 
          return "noprivilege"; 
      } 

  	tblQLDTTXAHoSoXetTuyenService = (TblQLDTTXAHoSoXetTuyenService) context.getBean("tbl_QLDTTXA_HoSoXetTuyenClient");
    tblQLDTTXADMKhoaService = (TblQLDTTXADMKhoaService) context.getBean("tbl_QLDTTXA_DM_KhoaClient");

    tblQLDTTXADMKhoaHocService = (TblQLDTTXADMKhoaHocService) context.getBean("tbl_QLDTTXA_DM_KhoaHocClient");

    tblQLDTTXADMNganhService = (TblQLDTTXADMNganhService) context.getBean("tbl_QLDTTXA_DM_NganhClient");

    tblQLDTTXALopService = (TblQLDTTXALopService) context.getBean("tbl_QLDTTXA_LopClient");
    tblQLDTTXADMTrangThaiHocVienService = (TblQLDTTXADMTrangThaiHocVienService) context.getBean("tbl_QLDTTXA_DM_TrangThaiHocVienClient");
	tblQLDTTXAHocVienService = (TblQLDTTXAHocVienService) context.getBean("tbl_QLDTTXA_HocVienClient");
	
	tblQLDTTXAHocVienPhieuLyLichService = (TblQLDTTXAHocVienPhieuLyLichService) context.getBean("tbl_QLDTTXA_HocVien_PhieuLyLichClient");
	
	tblQLDTTXAHocVienChuongTrinhHocService = (TblQLDTTXAHocVienChuongTrinhHocService) context.getBean("tbl_QLDTTXA_HocVien_ChuongTrinhHocClient");
	
	tblQLDTTXAChuongTrinhHocChiTietService = (TblQLDTTXAChuongTrinhHocChiTietService) context.getBean("tbl_QLDTTXA_ChuongTrinhHoc_ChiTietClient");
	
	tblQLDTTXAChuongTrinhHocService = (TblQLDTTXAChuongTrinhHocService) context.getBean("tbl_QLDTTXA_ChuongTrinhHocClient");
	
	tblQLDTTXAQuiDinhHocPhiService = (TblQLDTTXAQuiDinhHocPhiService) context.getBean("tbl_QLDTTXA_QuiDinhHocPhiClient");

	tblQLDTTXAHocVienHocPhiBienLaiService = (TblQLDTTXAHocVienHocPhiBienLaiService) context.getBean("tbl_QLDTTXA_HocVien_HocPhi_BienLaiClient");

	tblQLDTTXAHocVienTaiKhoanService = (TblQLDTTXAHocVienTaiKhoanService) context.getBean("tbl_QLDTTXA_HocVien_TaiKhoanClient");

	List<TblQLDTTXAQuiDinhHocPhi> tblQLDTTXAQuiDinhHocPhis = tblQLDTTXAQuiDinhHocPhiService.findAlltblQLDTTXAQuiDinhHocPhi(0, 0);
	
	if(tblQLDTTXAQuiDinhHocPhis.size() < 1)
		return Action.ERROR;
	
	TblQLDTTXAQuiDinhHocPhi tblQLDTTXAQuiDinhHocPhi = tblQLDTTXAQuiDinhHocPhis.get(0);	
	
	Format formatter = new SimpleDateFormat("DDDyyhhmmssSSS");
	
  	JSONArray jsonArr = (JSONArray) JSONSerializer.toJSON( saveStr );
	for(int i = 0; i < jsonArr.size() ; i++){
		JSONObject obj = jsonArr.getJSONObject(i);
	    int hoSoId = obj.getInt( "hoSoId" );
	    TblQLDTTXAHoSoXetTuyen hoSoXetTuyen = tblQLDTTXAHoSoXetTuyenService.gettblQLDTTXAHoSoXetTuyen(new Long(hoSoId));
	    
	    //insert HocVien- Ly lich
	    TblQLDTTXAHocVien tblQLDTTXAHocVien = insertHocVien(hoSoXetTuyen);
	    
	    if(tblQLDTTXAHocVien == null) return Action.ERROR;
	    
	    hoSoXetTuyen.setTrangThaiId(3);
	    tblQLDTTXAHoSoXetTuyenService.updatetblQLDTTXAHoSoXetTuyen(hoSoXetTuyen);
	    
	    //insert Chuong trinh hoc
	    if(!insertHocVienChuongTrinhHoc(tblQLDTTXAHocVien)){
	    	return Action.ERROR;
	    	
	    }
	    
	    Date today = new Date();
	    
	    /*TblQLDTTXAHocVienHocPhiBienLai tblQLDTTXAHocVienHocPhiBienLai = new TblQLDTTXAHocVienHocPhiBienLai();
	    tblQLDTTXAHocVienHocPhiBienLai.setSoBienLai("BLHP-" + formatter.format(today));
	    
	    DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); 
	       GregorianCalendar c = new GregorianCalendar(); 
	       c.setTime(today);
	       XMLGregorianCalendar d = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); 
	    tblQLDTTXAHocVienHocPhiBienLai.setNgayLap(d);
	    
	    tblQLDTTXAHocVienHocPhiBienLai.setHocVienId(tblQLDTTXAHocVien);
	    tblQLDTTXAHocVienHocPhiBienLai.setSoTien(tblQLDTTXAQuiDinhHocPhi.getTienNhapHoc());
	    tblQLDTTXAHocVienHocPhiBienLai.setDienGiai("Tiền nhập học");
	    
	    tblQLDTTXAHocVienHocPhiBienLaiService.createtblQLDTTXAHocVienHocPhiBienLai(tblQLDTTXAHocVienHocPhiBienLai);*/
	    
	    TblQLDTTXAHocVienTaiKhoan taikhoan = new TblQLDTTXAHocVienTaiKhoan();
	    taikhoan.setHocVienId(tblQLDTTXAHocVien);
	    //taikhoan.setSoDuTaiKhoan(tblQLDTTXAQuiDinhHocPhi.getTienNhapHoc());
	    taikhoan.setSoDuTaiKhoan(new Double(0.0));
	    
	    tblQLDTTXAHocVienTaiKhoanService.createtblQLDTTXAHocVienTaiKhoan(taikhoan);  
	    
	    
	}
	
	
  	  return Action.SUCCESS; 
  	  
        } 
        catch(Exception e){ 
        System.out.println("Loi Save tbl_QLDTTXA_HoSo_DiemXetTuyen Action"); 
       e.printStackTrace(); 
      return Action.ERROR; 
   } 
   } 

  private int khoaHocId;
  private int lopId;
  private int nganhId;

 private boolean insertHocVienChuongTrinhHoc(TblQLDTTXAHocVien hocVienId){
	 try{
	      List<ConditionReport> cons = new ArrayList<ConditionReport>(); 
  
	      /////////get chuong trinh hoc

		  if(khoaId != null && khoaId != 0){
			    ConditionReport con = new ConditionReport(); 
			    con.setCol("khoaId.id");
			    con.setValue1(khoaId);
			    con.setOperator("eq");
			    cons.add(con);
		  } else {
			    ConditionReport con = new ConditionReport(); 
			    con.setCol("khoaId.id");
			    con.setValue1(new Long(1));
			    con.setOperator("eq");
			    cons.add(con);
		  }
		  
		  if(true){
			    ConditionReport con = new ConditionReport(); 
			    con.setCol("ngayApDung");
			    con.setValue1("");
			    con.setOperator("max");
			    cons.add(con);
		  }
		 List<TblQLDTTXAChuongTrinhHoc> tblQLDTTXAChuongTrinhHocs = tblQLDTTXAChuongTrinhHocService.findtblQLDTTXAChuongTrinhHocByCondition(cons, 0, 0);
		 Long chuongTrinhHocId = new Long(0);
		 for(TblQLDTTXAChuongTrinhHoc tbl : tblQLDTTXAChuongTrinhHocs){
			 chuongTrinhHocId = tbl.getId();
		 }
		 
		 cons.clear();
		  if(true){
			    ConditionReport con = new ConditionReport(); 
			    con.setCol("chuongTrinhHocId.id");
			    con.setValue1(chuongTrinhHocId);
			    con.setOperator("eq");
			    cons.add(con);
		  }
		 List<TblQLDTTXAChuongTrinhHocChiTiet> tblQLDTTXAChuongTrinhHocChiTiets = tblQLDTTXAChuongTrinhHocChiTietService.findtblQLDTTXAChuongTrinhHocChiTietByCondition(cons, 0, 0);
		 for(TblQLDTTXAChuongTrinhHocChiTiet tblQLDTTXAChuongTrinhHocChiTiet : tblQLDTTXAChuongTrinhHocChiTiets){
			 TblQLDTTXAHocVienChuongTrinhHoc tblQLDTTXAHocVienChuongTrinhHoc = new TblQLDTTXAHocVienChuongTrinhHoc();

			 tblQLDTTXAHocVienChuongTrinhHoc.setHocVienId(hocVienId);
			 tblQLDTTXAHocVienChuongTrinhHoc.setHocKyId(tblQLDTTXAChuongTrinhHocChiTiet.getHocKyId());
			 tblQLDTTXAHocVienChuongTrinhHoc.setMonHocId(tblQLDTTXAChuongTrinhHocChiTiet.getMonHocId());
			 tblQLDTTXAHocVienChuongTrinhHoc.setHoanThanh(false);
			 
			 tblQLDTTXAHocVienChuongTrinhHocService.createtblQLDTTXAHocVienChuongTrinhHoc(tblQLDTTXAHocVienChuongTrinhHoc);
			 
		
			 
		 }
	      
		 return true;
	 } catch(Exception e){
		 
		 System.out.println("Loi insert chuong trinh hoc"); 
	       e.printStackTrace();
	       
	       return false;
	 }
	 
 }
 
 private String ngaylap;
  private TblQLDTTXAHocVien insertHocVien(TblQLDTTXAHoSoXetTuyen hoSoId){
	  try{

		  TblQLDTTXAHocVien tblQLDTTXAHocVien = new TblQLDTTXAHocVien();
		  
		  tblQLDTTXAHocVien.setHoSoId(hoSoId);
		  tblQLDTTXAHocVien.setChiNhanhId(hoSoId.getChiNhanhId());
		  tblQLDTTXAHocVien.setHoTen(hoSoId.getHoTen());
		  tblQLDTTXAHocVien.setTen(hoSoId.getTen());
		  tblQLDTTXAHocVien.setKhoaHocId(tblQLDTTXADMKhoaHocService.gettblQLDTTXADMKhoaHoc(new Long(khoaHocId)));
		  tblQLDTTXAHocVien.setKhoaId(hoSoId.getKhoaId());
		  tblQLDTTXAHocVien.setLopId(tblQLDTTXALopService.gettblQLDTTXALop(new Long(lopId)));
		  tblQLDTTXAHocVien.setNganhId(tblQLDTTXADMNganhService.gettblQLDTTXADMNganh(new Long(nganhId)));
		  tblQLDTTXAHocVien.setTrangThaiId(tblQLDTTXADMTrangThaiHocVienService.gettblQLDTTXADMTrangThaiHocVien(new Long(1)));
		  
		  Date ngayLap = new Date();
		  if(ngaylap != null && !ngaylap.equalsIgnoreCase("")){
		       DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); 
		       ngayLap = df.parse(ngaylap); 
		  }
	      GregorianCalendar c = new GregorianCalendar(); 
	      c.setTime(ngayLap);
	      XMLGregorianCalendar d = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); 
		  tblQLDTTXAHocVien.setNgayLap(d);
		  tblQLDTTXAHocVien.setId(tblQLDTTXAHocVienService.createtblQLDTTXAHocVien(tblQLDTTXAHocVien));
		  
		  TblQLDTTXAHocVienPhieuLyLich tblQLDTTXAHocVienPhieuLyLich = new TblQLDTTXAHocVienPhieuLyLich();
		  tblQLDTTXAHocVienPhieuLyLich.setDienThoai(hoSoId.getDienThoai());
		  tblQLDTTXAHocVienPhieuLyLich.setGioiTinh(hoSoId.isGioiTinh());
		  tblQLDTTXAHocVienPhieuLyLich.setHocVienId(tblQLDTTXAHocVien);
		  tblQLDTTXAHocVienPhieuLyLich.setNgaySinh(hoSoId.getNgaySinh());
		  tblQLDTTXAHocVienPhieuLyLich.setNoiSinh(hoSoId.getNoiSinh());
		  tblQLDTTXAHocVienPhieuLyLich.setThuongTru(hoSoId.getDiaChi());
		  tblQLDTTXAHocVienPhieuLyLich.setChoOHiennay(hoSoId.getDiaChiLienLac());
		  
		  tblQLDTTXAHocVienPhieuLyLichService.createtblQLDTTXAHocVienPhieuLyLich(tblQLDTTXAHocVienPhieuLyLich);
		  
		  
		  return tblQLDTTXAHocVien;
	  }
	  catch(Exception e){
		  System.out.println("LoinhapHoc : insert HocVien"); 
		     e.printStackTrace(); 
		  return null;
	  }

  }


public String getHoTen() {
	return hoTen;
}
public void setHoTen(String hoTen) {
	this.hoTen = hoTen;
}
public void setTblQLDTTXAHoSoDiemXetTuyens(
		Collection<TblQLDTTXAHoSoDiemXetTuyen> tblQLDTTXAHoSoDiemXetTuyens) {
	this.tblQLDTTXAHoSoDiemXetTuyens = tblQLDTTXAHoSoDiemXetTuyens;
}


public void setSaveStr(String saveStr) {
	this.saveStr = saveStr;
}
public Double getDiemDat() {
	return diemDat;
}
public void setDiemDat(Double diemDat) {
	this.diemDat = diemDat;
}
public Long getKhoaId() {
	return khoaId;
}
public void setKhoaId(Long khoaId) {
	this.khoaId = khoaId;
}
public List<TblQLDTTXADMKhoa> getTblQLDTTXADMKhoas() {
	return tblQLDTTXADMKhoas;
}
public void setTblQLDTTXADMKhoas(List<TblQLDTTXADMKhoa> tblQLDTTXADMKhoas) {
	this.tblQLDTTXADMKhoas = tblQLDTTXADMKhoas;
}
public TblQLDTTXADMKhoa getTblQLDTTXADMKhoa() {
	return tblQLDTTXADMKhoa;
}
public void setTblQLDTTXADMKhoa(TblQLDTTXADMKhoa tblQLDTTXADMKhoa) {
	this.tblQLDTTXADMKhoa = tblQLDTTXADMKhoa;
}
public Date getToday() {
	return today;
}
public List<TblQLDTTXADMKhoaHoc> getTblQLDTTXADMKhoaHocs() {
	return tblQLDTTXADMKhoaHocs;
}
public List<TblQLDTTXALop> getTblQLDTTXALops() {
	return tblQLDTTXALops;
}
public void setTblQLDTTXALops(List<TblQLDTTXALop> tblQLDTTXALops) {
	this.tblQLDTTXALops = tblQLDTTXALops;
}
public List<TblQLDTTXADMNganh> getTblQLDTTXADMNganhs() {
	return tblQLDTTXADMNganhs;
}
public int getKhoaHocId() {
	return khoaHocId;
}
public void setKhoaHocId(int khoaHocId) {
	this.khoaHocId = khoaHocId;
}
public int getNganhId() {
	return nganhId;
}
public void setNganhId(int nganhId) {
	this.nganhId = nganhId;
}
public int getLopId() {
	return lopId;
}
public void setLopId(int lopId) {
	this.lopId = lopId;
}
public String getNgaylap() {
	return ngaylap;
}
public void setNgaylap(String ngaylap) {
	this.ngaylap = ngaylap;
}
public void setPageSize(int pageSize) {
	this.pageSize = pageSize;
}
public void setPage(int page) {
	this.page = page;
}
public void setPages(int pages) {
	this.pages = pages;
}
public void setDataString(String dataString) {
	this.dataString = dataString;
}


 } 
 
